import { request } from '@/api/request';
import { HttpMethod } from '@/services/types';

/**
 * GET /slides/:id 轮播详情
 * @param id
 * @param options
 */
export async function resSlideDetail(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<API.SlideStruct>>('/slides/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /slides 轮播列表
 * @param params
 * @param options
 */
export async function resSlides(
  params?: Partial<API.PaginationQueryBase & { status: number }>,
  options?: { [key: string]: any }
) {
  return request<API.PaginationResult<API.SlideStruct>>('/slides', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}

/*  admin  */

/**
 * DELETE /admin/slides/:id 轮播删除
 * @param id
 * @param options
 */
export async function resDeleteSlidesAdmin(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/admin/slides/' + id, {
    method: HttpMethod.DELETE,
    ...(options || {}),
  });
}

/**
 * PATCH /admin/slides/seq/:id 轮播排序
 * @param id
 * @param params
 * @param options
 */
export async function resSeqSlidesAdmin(
  id: number,
  params: API.SeqSlideParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/admin/slides/seq/' + id, {
    method: HttpMethod.PATCH,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /admin/slides/status/:id 轮播启用和禁用
 * @param id
 * @param options
 */
export async function resStatusSlidesAdmin(
  id: number,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/admin/slides/status/' + id, {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}

/**
 * POST /admin/slides 添加轮播
 * @param params
 * @param options
 */
export async function resAddSlidesAdmin(
  params: API.ChangeSlideParams,
  options?: { [key: string]: any }
) {
  return request<R<API.SlideStruct>>('/admin/slides', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * PUT /admin/slides/:id 修改轮播
 * @param id
 * @param params
 * @param options
 */
export async function resChangeSlidesAdmin(
  id: number,
  params: API.ChangeSlideParams,
  options?: { [key: string]: any }
) {
  return request<R<null>>('/admin/slides/' + id, {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}
